//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.orphan.supplier.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orphan.supplier.mapper.TenderMapper;
import com.orphan.supplier.po.Goods;
import com.orphan.supplier.po.Supplier;
import com.orphan.supplier.po.Tender;
import com.orphan.supplier.po.TenderCall;
import com.orphan.supplier.service.ITenderService;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("iTenderService")
public class TenderServiceImpl extends ServiceImpl<TenderMapper, Tender> implements ITenderService {
    @Resource
    private TenderMapper tenderMapper;

    public TenderServiceImpl() {
    }

    public List<Tender> list() {
        List<Tender> tenders = this.tenderMapper.findAll();
        Iterator var2 = tenders.iterator();

        while(var2.hasNext()) {
            Tender tender = (Tender)var2.next();
            tender.setSupplier((Supplier)null);
        }

        return tenders;
    }

    public List<Tender> thisUser(String number) {
        return this.tenderMapper.selectTendersByUserName(number);
    }

    public Tender getByNum(String number) {
        return this.tenderMapper.getByNum(number);
    }

    public boolean add(Double price, int providedAmount, String call, String username, int goodsId) {
        Tender tender = this.makeTender(price, providedAmount, call, username, goodsId);
        return this.tenderMapper.add(tender) > 0;
    }

    public boolean updateTender(String tenderNumber, Double price,int amount) {
        Tender tender = this.makeTender(price, amount, tenderNumber, (String)null, 0);
        tender.setNumber(tenderNumber);
        return this.tenderMapper.updateTender(tender);
    }

    public boolean cancel(String tenderNumber) {
        return this.tenderMapper.cancel(tenderNumber);
    }

    private Tender makeTender(Double price, int providedAmount, String call, String username, int goodsId) {
        Tender tender = new Tender();
        tender.setPrice(price);
        TenderCall call1 = new TenderCall();
        call1.setNumber(call);
        tender.setCall(call1);
        tender.setProvidedAmount(providedAmount);
        Supplier supplier = new Supplier();
        supplier.setUsername(username);
        tender.setSupplier(supplier);
        String s = UUID.randomUUID().toString();
        tender.setNumber(s);
        tender.setTenderTime(new Date());
        Goods goods = new Goods();
        goods.setId(goodsId);
        tender.setGoods(goods);
        return tender;
    }
}
